//
//  TitleButton.swift
//  CXSwiftWB
//
//  Created by meidaeriOS on 2017/5/22.
//  Copyright © 2017年 meidaer. All rights reserved.
//

import UIKit

class TitleButton: UIButton {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
//    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
//    }
    
    func setupUI() {
        setImage(UIImage.init(named: "navigationbar_arrow_down"), for: UIControlState.normal)
        setImage(UIImage.init(named: "navigationbar_arrow_up"), for: UIControlState.selected)
        
        setTitleColor(UIColor.darkGray, for: UIControlState())
        sizeToFit()
    }
    
    override func setTitle(_ title: String?, for state: UIControlState) {
        super.setTitle(title ?? "" + " ", for: state)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        // 和OC的不太一样， swift 语法允许我们直接修改一个对象的结构体属性的成员
        titleLabel?.frame.origin.x = 0
        imageView?.frame.origin.x = titleLabel!.frame.width
    }

}
